<%@ Page Language="C#" MasterPageFile="~/SurveyHost.Master" AutoEventWireup="true"
    MaintainScrollPositionOnPostback="true" CodeBehind="Measures.aspx.cs" ValidateRequest="false"
    Inherits="SurveyHost.Web.Admin.Measures" Title="Edit Measures" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="post">
        <h1 class="title">
            Edit Measures
        </h1>
        <p class="byline">
            You can edit, delete or create new measures here
        </p>
        <div class="entry">
            <asp:FormView ID="FormView1" runat="server" DataSourceID="MeasureDetailsDataSource"
                Width="100%" OnItemInserting="FormView1_ItemInserting" 
                onitemdeleted="FormView1_ItemDeleted" oniteminserted="FormView1_ItemInserted" 
                onitemupdated="FormView1_ItemUpdated" DataKeyNames="MeasureName">
                <EditItemTemplate>
                    <div style="width: 50%; float: left;">
                        Rank:&nbsp;&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                            ErrorMessage="* Required" ControlToValidate="RankTextBox" Display="dynamic"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Must be between 1 and 1000"
                            Type="integer" MinimumValue="1" MaximumValue="1000" ControlToValidate="RankTextBox"
                            Display="dynamic"></asp:RangeValidator><br />
                        <asp:TextBox ID="RankTextBox" runat="server" MaxLength="4" Text='<%# Bind("Rank") %>'
                            ToolTip="Rank is the order in which measures are presented"></asp:TextBox>
                    </div>
                    <div style="width: 50%; float: right;">
                        Default Answer Type:<br />
                        <asp:DropDownList ID="AnswerTypeDropdown" runat="server" DataSourceID="AnswerTypeDatasource"
                            Width="100%" DataTextField="AnswerTypeName" DataValueField="AnswerTypeName" SelectedValue='<%# Bind("DefaultAnswerTypeName") %>'
                            ToolTip="The default format for answers to questions in this measure">
                        </asp:DropDownList>
                    </div>
                    <div class="measureName" style="clear: both;">
                        <p>
                            Measure Name:<br />
                            <asp:TextBox ID="MeasureNameTextBox" Width="100%" runat="server" ReadOnly="true" Text='<%# Bind("MeasureName") %>'
                                 ToolTip="A Measure's name is its unique identifier and cannot be changed once set"></asp:TextBox>
                        </p>
                    </div>
                    <div class="measureInstructions">
                        Instructions:<br />
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Instructions") %>'
                            ToolTip="Instructions are shown to the user on the top of the survey page" TextMode="multiLine"
                            Rows="6" Width="100%"></asp:TextBox>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                            Text="Update">
                        </asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel">
                        </asp:LinkButton></div>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <div style="width: 50%; float: left;">
                        Rank:&nbsp;&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                            ErrorMessage="* Required" ControlToValidate="RankTextBox" Display="dynamic"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Must be between 1 and 1000"
                            Type="integer" MinimumValue="1" MaximumValue="1000" ControlToValidate="RankTextBox"
                            Display="dynamic"></asp:RangeValidator><br />
                        <asp:TextBox ID="RankTextBox" runat="server" MaxLength="4" Text='<%# Bind("Rank") %>'
                            ToolTip="Rank is the order in which measures are presented"></asp:TextBox>
                    </div>
                    <div style="width: 50%; float: right;">
                        Default Answer Type:<br />
                        <asp:DropDownList ID="AnswerTypeDropdown" runat="server" DataSourceID="AnswerTypeDatasource"
                            Width="100%" DataTextField="AnswerTypeName" DataValueField="AnswerTypeName" SelectedValue='<%# Bind("DefaultAnswerTypeName") %>'
                            ToolTip="The default format for answers to questions in this measure">
                        </asp:DropDownList>
                    </div>
                    <div style="clear: both;">
                        <p>
                            Measure Name:&nbsp;&nbsp;
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required"
                                ControlToValidate="MeasureNameTextBox"></asp:RequiredFieldValidator>
                            <asp:TextBox ID="MeasureNameTextBox" runat="server" Text='<%# Bind("MeasureName") %>'
                                Width="100%" ToolTip="Important!  Once a measure has been saved its name cannot be changed!"></asp:TextBox>
                        </p>
                        <div>
                            Instructions:
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Instructions") %>' Width="100%"
                                ToolTip="Instructions are shown to the user on the top of the survey page" TextMode="multiLine"
                                Rows="2"></asp:TextBox>
                        </div>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                            Text="Insert">
                        </asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel">
                        </asp:LinkButton></div>
                </InsertItemTemplate>
                <ItemTemplate>
                    <div style="width: 50%; float: left;">
                        Rank:&nbsp;&nbsp;<asp:Label ID="RankLabel" runat="server" Text='<%# Bind("Rank") %>'></asp:Label>
                    </div>
                    <div style="width: 50%; float: right;">
                        Default Answer Type:&nbsp;&nbsp;<asp:Label ID="DefaultAnswerTypeNameLabel" runat="server"
                            Text='<%# Bind("DefaultAnswerTypeName") %>'></asp:Label>
                    </div>
                    <div style="clear: both;">
                        <p>
                            Measure Name:&nbsp;&nbsp;<asp:Label ID="MeasureNameLabel" runat="server" Text='<%# Bind("MeasureName") %>'></asp:Label>
                        </p>
                    </div>
                    <div>
                        Instructions:
                        <asp:Label ID="instructionLabel" runat="server" Text='<%# Bind("Instructions") %>'
                            Width="100%" ToolTip="Instructions are shown to the user on the top of the survey page"></asp:Label>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                            Text="Edit">
                        </asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                            Text="Delete">
                        </asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                            Text="New">
                        </asp:LinkButton>
                    </div>
                </ItemTemplate>
                <EmptyDataTemplate>
                <p>To view the details of a Measure, click the &quot;Select&quot; link of the Measure you wish 
                    to inspect in the grid below.</p>
                <p>To edit a Measure, select it and then click the &quot;Edit&quot; link that appears in this 
                    section.</p>
                <p>To delete a Measure, select it in the grid below and then click the &quot;Delete&quot; link 
                    that appears in this section.</p>
                <p> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                        Text="To create a new Measure, click here.">
                    </asp:LinkButton></p>                    
                </EmptyDataTemplate>
            </asp:FormView>
        </div>
    </div>
    <div class="post">
        <h1 class="title">
            Measures
        </h1>
        <p class="byline">
            Select a measure to edit or delete it
        </p>
        <div class="entry">
            <asp:GridView ID="GridView1" runat="server" DataSourceID="MeasureDataSource" AutoGenerateColumns="False"
                BackColor="White" BorderStyle="None" CellPadding="3" GridLines="None" Width="100%"
                DataKeyNames="MeasureName" OnRowDeleting="GridView1_RowDeleting" AllowPaging="True"
                OnRowUpdating="GridView1_RowUpdating" PageSize="50">
                <RowStyle CssClass="gridRowStyle" BackColor="#EEEEEE" ForeColor="Black" />
                <AlternatingRowStyle CssClass="gridAlternatingRowStyle" BackColor="Gainsboro" />
                <PagerStyle CssClass="gridPagerStyle" BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <HeaderStyle CssClass="callOutStyle" Font-Bold="True" BackColor="#CCCCCC" ForeColor="Black"
                    HorizontalAlign="Left" />
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <SelectedRowStyle CssClass="gridSelectedRowStyle" BackColor="#008A8C" Font-Bold="True"
                    ForeColor="White" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" >
                        <HeaderStyle Width="4em" />
                    </asp:CommandField>
                    <asp:BoundField DataField="Rank" HeaderText="Rank" SortExpression="Rank">
                        <HeaderStyle Width="2em" />
                        <ItemStyle Width="32px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="MeasureName" HeaderText="Name" SortExpression="MeasureName"
                        ReadOnly="True" >
                        <HeaderStyle Width="6em" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="Instructions" SortExpression="Instructions">
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Instructions") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:Label ID="ResultText" runat="server" EnableViewState="false" Visible="false"></asp:Label>
        </div>
    </div>
    <asp:ObjectDataSource ID="MeasureDataSource" runat="server" 
        DeleteMethod="Delete" SelectMethod="GetOrderedCollection" 
        TypeName="SurveyHost.Core.DAL.MeasureController" 
        OldValuesParameterFormatString="original_{0}" 
    DataObjectTypeName="SurveyHost.Core.DAL.Measure" InsertMethod="Add" 
    UpdateMethod="Update">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="MeasureDetailsDataSource" runat="server" DeleteMethod="Delete"
        InsertMethod="Add" OldValuesParameterFormatString="original_{0}" SelectMethod="FetchByID"
        TypeName="SurveyHost.Core.DAL.MeasureController" UpdateMethod="Update" 
        DataObjectTypeName="SurveyHost.Core.DAL.Measure">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="MeasureName" PropertyName="SelectedValue"
                Type="Object" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="AnswerTypeDatasource" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="FetchAll" TypeName="SurveyHost.Core.DAL.AnswerObjectTypeController">
    </asp:ObjectDataSource>
</asp:Content>
